<?php

include_once 'Conexion.php';

class Pago extends Conexion {

    public function getMontoPagos($idFactura) {

        $this->conectar();

        $sql = "SELECT monto FROM pago WHERE idfactura=$idFactura";

        $sqlResult = $this->ejecutarConsulta($sql);

        $this->desconectar();

        if ($sqlResult == false) {
            return 0;
        } else {

            //$arrEntregas = mysql_fetch_array($sqlResult);

            $acum = 0;

            while ($arrEntregas = mysql_fetch_array($sqlResult)) {
                $tempPagos = $arrEntregas;

                $acum = $acum + $tempPagos['monto'];
            }

            return $acum;
        }
    }
    
    public function registrar ($idFactura, $fecha, $monto) {
        
        $this->conectar();
        
        $resul =  $this->ejecutarQuery("INSERT INTO pago(idfactura, fecha, monto) VALUES ($idFactura, '$fecha', $monto)");
        
        $this->desconectar();
        
        return $resul;
    }


    public function getPagosFacturaById ($idFactura) {
        $this->conectar();

        $sql = "SELECT fecha, monto FROM pago WHERE idfactura=$idFactura";

        $sqlResult = $this->ejecutarConsulta($sql);

        $this->desconectar();

        return $sqlResult;
    }
}
?>